<template>
  <div class="home-banner">
    <el-carousel height="500px" :interval="2000">
      <el-carousel-item v-for="item in bannerData" :key="item.id">
        <img :src="item.imgUrl" alt="轮播图" />
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
export default {
  name: 'HomeBanner',
  props: {},
  data() {
    return {
      bannerData: []
    }
  },
  async fetch() {
    await this.getBanner()
  },
  mounted() {},
  methods: {
    /** 获取轮播图 */
    async getBanner() {
      const { data: res } = await this.$getBanner()
      if (res.code !== '1') return this.$message.error(res.msg)
      this.bannerData = res.result
    }
  }
}
</script>

<style scoped lang="scss">
.home-banner {
  width: 1240px;
  height: 500px;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 98;

  img {
    width: 100%;
    height: 500px;
  }
}
</style>
